package com.yuexunit.operationman.nbsy.module.nurse.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.nurse.Bean.NurseBean;
import com.yuexunit.operationman.nbsy.module.nurse.ui.Act_Ops_Preview;

import org.kymjs.kjframe.ui.KJFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by chenss on 2017/7/10 0010.
 */

public class Fragment_preoperative extends KJFragment {

    @Bind(R.id.join_date)
    TextView joinDate;
    @Bind(R.id.skin_conditions)
    TextView skinConditions;
    @Bind(R.id.drug_allergy_history)
    TextView drugAllergyHistory;
    @Bind(R.id.frag_pre_01)
    TextView fragPre01;
    @Bind(R.id.frag_pre_02)
    TextView fragPre02;
    @Bind(R.id.frag_pre_03)
    TextView fragPre03;
    @Bind(R.id.frag_pre_04)
    TextView fragPre04;
    @Bind(R.id.frag_pre_05)
    TextView fragPre05;
    @Bind(R.id.frag_pre_06)
    TextView fragPre06;
    @Bind(R.id.frag_pre_07)
    TextView fragPre07;
    @Bind(R.id.frag_end_04)
    TextView fragEnd04;
    @Bind(R.id.frag_end_05)
    TextView fragEnd05;
    @Bind(R.id.frag_end_06)
    TextView fragEnd06;
    @Bind(R.id.BP_Sign)
    TextView BPSign;
    @Bind(R.id.surgery_name)
    TextView surgeryName;
    private Act_Ops_Preview aty;
    protected View mMainView;

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
        aty = (Act_Ops_Preview) getActivity();
        mMainView = inflater.inflate(R.layout.fragment_preoperative, container, false);
        ButterKnife.bind(this, mMainView);
        return mMainView;
    }

    @Override
    protected void initData() {
        for (NurseBean.ObjectEntity.NursingItemListEntity p : AppConfig.NURSEBEAN.getObject().getNursingItemList()) {
            switch (p.getItemCode()) {
                case "BP_Time":
                    joinDate.setText(p.getItemValue());
                    break;
                case "BP_ShouShuShi":
                    surgeryName.setText(p.getItemValue());
                    break;
                case "BP_BingRenHeDui":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            fragPre01.setText("有");
                        } else if (skin[1].equals("1")) {
                            fragPre01.setText("无");
                        }
                    }
                    break;
                case "BP_ShouShuBuWeiHeDui":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            fragPre02.setText("有");
                        } else if (skin[1].equals("1")) {
                            fragPre02.setText("无");
                        }
                    }
                    break;
                case "BP_ShenZhi":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        String[] arrays = getResources().getStringArray(R.array.nursing_pre_09);
                        if (skin[0].equals("1")) {
                            fragPre03.setText(arrays[0]);
                        } else if (skin[1].equals("1")) {
                            fragPre03.setText(arrays[1]);
                        } else if (skin[2].equals("1")) {
                            fragPre03.setText(arrays[2]);
                        }
                    }
                    break;
                case "BP_ShenJingMaiChuanCi":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            fragPre04.setText("有");
                        } else if (skin[1].equals("1")) {
                            fragPre04.setText("无");
                        }
                    }
                    break;
                case "BP_JingMaiShuYe":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            fragPre05.setText("有");
                        } else if (skin[1].equals("1")) {
                            fragPre05.setText("无");
                        }
                    }
                    break;
                case "BP_WeiGuan":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            fragPre06.setText("有");
                        } else if (skin[1].equals("1")) {
                            fragPre06.setText("无");
                        }
                    }
                    break;
                case "BP_DaoNiaoGuan":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            fragPre07.setText("有");
                        } else if (skin[1].equals("1")) {
                            fragPre07.setText("无");
                        }
                    }
                    break;
                case "BP_Skin":
                    if (p.getItemValue().length() > 0) {
                        String[] arrays = getResources().getStringArray(R.array.nursing_pre_01);
                        if (p.getItemValue().equals("1")) {
                            skinConditions.setText(arrays[0]);
                        } else if (p.getItemValue().equals("0")) {
                            skinConditions.setText(arrays[1] + ":" + p.getItemOther());
                        }
                    }
                    break;
                case "BP_YaoWuGuoMing":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        String[] arrays = getResources().getStringArray(R.array.nursing_pre_02);
                        if (skin[0].equals("1")) {
                            drugAllergyHistory.setText(arrays[0]);
                        } else if (skin[1].equals("1")) {
                            drugAllergyHistory.setText(arrays[1] + ":" + skin[2]);
                        }
                    }
                    break;
//                case "BP_Over_Sign":
//                    if (p.getItemName().length() > 0) {
//                        BPSign.setText(p.getItemName());
//                    }
//                    break;
                case "AP_JunBao":
                    if (p.getItemOther().length() > 0) {
                        String[] medicine = p.getItemOther().split(";", -1);
                        String content ="";
                        for(int i = 0;i<medicine.length;i++)
                        {
                            content+=medicine[i]+"\n";
                        }

                        fragEnd04.setText(content);
                    }
                    break;
                case "AP_JunBaoJianCe":
                    if (p.getItemValue().length() > 0) {
                        if (p.getItemValue().equals("1")) {
                            fragEnd05.setText("合格");
                        }
                    }
                    break;
                case "WJB_Doctor_Sign":
                    if (p.getItemName().length() > 0) {
                        fragEnd06.setText(p.getItemName());
                    }
                    break;
                case "WJB_Nurse_Sign":
                    if (p.getItemName().length() > 0) {
                        BPSign.setText(p.getItemName());
                    }
                    break;
            }
        }
    }
}
